/* 
 * File:   PixelDispenser.cpp
 * Author: brady
 * 
 * Created on June 23, 2011, 6:49 PM
 */

#include <core/PixelDispenser.h>

PixelDispenser::PixelDispenser() {
}

PixelDispenser::PixelDispenser(int xResolution, int yResolution){
    this->xResolution = xResolution;
    this->yResolution = yResolution;
    this->currentX = 0;
    this->currentY = 0;
    this->totalPixels = xResolution*yResolution;
    this->currentPixel = 0;
    empty = (xResolution <= 0) || (yResolution <= 0);

}

PixelDispenser::PixelDispenser(const PixelDispenser& orig) {
}

PixelDispenser::~PixelDispenser() {
}

Pixel PixelDispenser::getPixel(){
    if(empty){
        return Pixel(-1,-1);
    }

    Pixel px = Pixel(currentX, currentY);
    currentX++;
    if(currentX >= xResolution){
        currentX = 0;
        currentY++;
        if(currentY >= yResolution){
            empty = true;
        }
    }
    currentPixel++;
    return px;
}

bool PixelDispenser::isEmpty(){
    return empty;
}

double PixelDispenser::completion(){
    return ((double)currentPixel/(double)totalPixels);
}
